﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：OAuthExtensions.cs
// 功能描述：TongTongMall.Oauth2.0
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using Microsoft.Owin;
using Microsoft.Owin.Extensions;
using Microsoft.Owin.Security.OAuth;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TongTongMall.Dependecy;
using TongTongMall.Oauth2._0.Client;

namespace TongTongMall.Oauth2._0
{
    public static class OAuthExtensions
    {
        private static OAuthAuthorizationServerOptions OAuthOptions { get; set; }
        public static void UseOAuthServer(this IAppBuilder app, OAuthAuthorizationServerOptions Options = null)
        {
            OAuthOptions = Options ?? new OAuthAuthorizationServerOptions();
            app.Use(typeof(OAuthAuthorizationServerMiddlewareExtended), app, OAuthOptions);

            //app.Use<OAuthAuthorizationServerMiddlewareExtend>(app, new OAuthBearerAuthenticationOptions());
            //app.UseOAuthAuthorizationServer(OAuthOptions); 
        }

        public static void UseOAuthClient(this IAppBuilder app)
        {
            //自定义token验证过程
            app.Use<OAuthBearerAuthenticationMiddlewareExtended>(app, new OAuthBearerAuthenticationOptions());
            app.UseStageMarker(PipelineStage.Authenticate);
        }
    }
}
